package com.ftg.learn.chapter02.util;

import com.ftg.learn.chapter02.entity.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;

/**
 * 当前类，相当于一个配置文件
 * @author kangjx
 * @date 2022/11/3
 */
@Configuration
@PropertySource(value = {"my.properties"},encoding = "UTF-8")
public class MyJavaXml {

    /**
     * bean  不声明任何时，注入的组件id为方法的名称
     * <bean id = user1 class="..."></bean>
     * @return
     */
    @Bean(value = "ur")
    @Primary
    public User user1(){
        User u1 = new User();
        u1.setName("张三");
        return u1;
    }

    @Bean
    public User user2(){
        User u2 = new User();
        u2.setName("王二狗");
        System.out.println(u2.getName());
        return u2;
    }


}
